package com.iseastar.guojiang.team.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.iseastar.guojiang.model.CourierTeamDetailBackBean;
import com.shouhuobao.station.R;
import com.shouhuobao.take.utils.DateUtils;
import com.shouhuobao.take.weight.CircularImage;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;
import droid.frame.utils.GlideUtil;
import droid.frame.utils.lang.Str;

/**
 * @author 李澄锋<br>
 * 2018/6/19
 */
public class CourierTeamDetailMonthAdapter extends BaseAdapterExt<CourierTeamDetailBackBean.CourierTaskDto> {

    public CourierTeamDetailMonthAdapter(ArrayList<CourierTeamDetailBackBean.CourierTaskDto> items, Activity context) {
        super(items, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        ViewHolder viewHolder = null;
        if (convertView == null || convertView.getTag() == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_courier_team_detail_month, parent, false);
            viewHolder.courierHeadIV = convertView.findViewById(R.id.courier_title_image);
            viewHolder.teamLeaderNameTV = convertView.findViewById(R.id.courier_name_tv);
            viewHolder.joinTeamTimeTV = convertView.findViewById(R.id.join_time_tv);
            viewHolder.courierInfoTV = convertView.findViewById(R.id.courier_message_tv);
            viewHolder.orderQuantityTV = convertView.findViewById(R.id.order_quantity_tv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        CourierTeamDetailBackBean.CourierTaskDto item = getItem(position);
        GlideUtil.loadImage(context, item.getImagePath(), R.drawable.setting_head_hover_default, viewHolder.courierHeadIV);
        if (Str.isEmpty(item.getName())) {
            viewHolder.teamLeaderNameTV.setText(item.getNickName() + "（）");
        } else {
            viewHolder.teamLeaderNameTV.setText(item.getNickName() + "（" + item.getName().substring(0, 1) + "师傅）");
        }
        viewHolder.joinTeamTimeTV.setText(DateUtils.getTimeYMDHMSFormat().format(item.getAuditTime()).split(" ")[0] + " 加入");
        viewHolder.courierInfoTV.setText(item.getSex() + "，" + item.getProvinceName() + "人，" + item.getAge() + "岁   " + item.getScore() + "分");
        viewHolder.orderQuantityTV.setText("累计完成" + item.getTaskCount() + "单，本月总收入" + item.getTaskProfit() + "元");
        return convertView;
    }

    private class ViewHolder {
        CircularImage courierHeadIV;//火箭侠头像
        TextView teamLeaderNameTV;//队长名字
        TextView joinTeamTimeTV;//加入时间
        TextView courierInfoTV;//男，四川人，33岁    4.4分
        TextView orderQuantityTV;//累计完成xxx单，本月总收入xxx元
    }
}
